import { createApp } from '../libs/vue.browser.js';

let app = createApp({
  data() {
    return {
      title: 'vue3你好！',
      user: {
        username: '',
        pwd: '',
      },
      menus: [
        { title: '黑暗骑士的网站', href: 'https://huhuiyu.top' },
        { title: '哔哩哔哩', href: 'https://bilibili.com' },
      ],
    };
  },
  methods: {
    showUser() {
      console.log(app.user);
      alert(JSON.stringify(this.user, null, 2));
    },
  },
});

app.mount('#app');

// 查询字符串的补充知识点
// 转换查询字符串?id=111&name=darkknight&sex=m为{id:111,name:"..."}
// `是否删除"${dept.name}"？`
// "是否删除"+dept.name+"?"
// `编号：${id},姓名：${name}"${sex}"`

let info = '?id=111&name=darkknight&sex=m';
// 去掉?
info = info.substring(1);
console.log(info);
// 分解多组（标识是&）
let infos = info.split('&');
console.log(infos);

let objJson = {};

// 分解参数的名称和值（标识是=）
infos.forEach((item, i) => {
  console.log(item, i);
  let items = item.split('=');
  console.log(items[0], items[1]);
  objJson[items[0]] = items[1];
});

console.log(objJson);
